Example: Extract the username in the Interview Portlet

Example: Extract the username in the Interview Portlet

This sample illustrates the use of OnPortletRequestEvent to extract the user nickname property from the USER_INFO object provided by the portal server.

The sample code for this plugin can be found in the examples/interview-portlet/username-extractor directory.

The example consists of:

<user-attribute>
      <description>User Nickname</description>
      <name>user.name.nickName</name>
</user-attribute>

PortletUsernameExtractor

This class is an event handler for OnPortletRequestEvent. In the handleEvent, method, the user nickname is extracted using the following code:

Map userInfo = (Map)
event.getPortletRequest().getAttribute(PortletRequest.USER_INFO);
if (userInfo != null && !userInfo.isEmpty()) {
      String nickName = (String) userInfo.get("user.name.nickName");
}

The nickname can then be stored as an attribute in the Portlet Request using the following code:

event.getPortletRequest().setAttribute("user-id", nickName);

Extracting other attributes

The Oracle Policy Automation Interview Portlet by default exposes the nickname by way of portlet.xml. If other attributes need to be accessed by custom plugins, they need to be declared in portlet.xml.